<?php
    /**
    * View detail Real Estate
    * @author trungdt
    * @since June 25, 2011
    * 
    * Change logs
    * 
    */

    if (!defined('EXPONENT')) exit;
    
    global $db;
    $id=-1;
    $sql_where="";
   
    if (isset($_REQUEST['id']))
    {
        $id=$_REQUEST['id'];
        if (intval($id) > 0)
        {
            $id=intval($id);
            $sql_where=" id = {$id}";
        }
        else
        {
            header("Location: /index.php");
            die();
        }

        $config=$db->selectObject("bdsmodule_config","location_data = '".serialize($loc)."'");

        $template = new template('bdsmodule',"_view_detail",$loc);

        $project= $db->selectObject('bds'," location_data='".serialize($loc)."' AND {$sql_where} ");

        if ($project && (
                // if not public, but have permission
                (($project->bds_trangthai == 0) && (exponent_permissions_check('administrate',$loc) || 
                exponent_permissions_check('edit',$loc) ||
                exponent_permissions_check('create',$loc)))
                || ($project->bds_trangthai > 1) // =2 or =3
            )
        )
        {
            //location
            $province=duanmodule::_GetProvince_byID(intval($project->province_id));
            $ward = duanmodule::_GetWard_byID(intval($project->province_ward_id), ($project->province_id));
            $project->location=$ward->name ." - ".$province->name;
            
            // thumbnail file process
            $temp=explode(";",$project->hinhanh);
            $sql_where="";
            foreach ($temp as $k=>$v){
                if ($v!="")
                {
                    if ($sql_where == "")
                        $sql_where="(id = {$v})";
                    else
                        $sql_where=" OR (id = {$v})";
                }
            }
            $files=$db->selectObjects('file',$sql_where);
            $project->image_count=0;
            foreach ($files as $k=>$v)
            {
                $project->image_count++;
                $temp_name=$project->image_count-1;
                $temp_name = "image_path{$temp_name}";
                $project->$temp_name = BASE_URL."/".$v->directory.'/'.$v->filename;
            }
            
            $template->register_permissions(array('administrate','configure','edit','create','delete'),$loc);
            _ab_theme_action_register_title($project->name,1,1);
            _ab_theme_action_register_title(strip_tags($project->name),1,0);
            $template->assign('project', $project);
            $template->assign('config', $config);

            exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_ACTION);
            $template->output();
        }
        else
        {
            echo SITE_404_HTML;
        }
    }
    else
    {
        // For SEO purpose, we must list all project
        // in-case, we dont have ID, call action list to show all projects
        // list all project (for management only - hehe)
        $_REQUEST['page']=1;
        include("list.php");
    }


?>
